package tptecnicas.logging.filters;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import tptecnicas.logging.MessageInfo;

/**
 * Filtro de los mensajes a loguear, segun un patron 
 * RegEx preconfigurado.
 */
public class RegexFilter implements Filter {

	private Pattern patternToMatch;
	private Matcher matcher;
	
	/**
	 * Constructor:
	 * @param regEx to be matched
	 * */
	public RegexFilter(String regEx){
		
		this.patternToMatch = Pattern.compile(regEx);		
		
	}
	
	
	@Override
	public boolean shouldBeFiltered(MessageInfo message) {
		
		matcher = this.patternToMatch.matcher(message.getMessage());
		
		return matcher.find();
	}

}
